package com.unicom.room.controller;

import java.util.Date;

import com.unicom.room.common.JsonResult;
import com.unicom.room.model.Room;
import com.unicom.room.service.RoomService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * //房间信息管理
 * zhangxin
 */


@RestController
@RequestMapping("/hotelMgmt/roomInfoMgmt")
public class RoomInfoController {

	private static final Logger logger = LoggerFactory.getLogger(RoomInfoController.class);

	@Autowired
	RoomService roomService;

	@RequestMapping(value = "/listRoom", method = RequestMethod.GET)
	public JsonResult listRoom(){
		return new JsonResult("00000", roomService.listRooms());
	}
	//新增房间
	@RequestMapping(value = "/insertRoom", method = RequestMethod.POST)
	public JsonResult insertRoom(@RequestBody Room room){
		try {
			room.setCreateTime(new Date());
			//	logger.info(new Date +"这是新日期。。。。。");
			System.out.println("``````新增房间时间"+new Date()+"```````````");
			roomService.insertRoom(room);
		} catch(Exception e){
			return new JsonResult("500");
		}
		return new JsonResult("00000");
	}

	//修改房间信息
	@RequestMapping(value = "/updateRoom", method = RequestMethod.PUT)
	public JsonResult updateRoom(@RequestBody Room room){
		try {
			room.setUpdateTime(new Date());
			System.out.println("``````更新房间时间"+new Date()+"```````````");
			roomService.updateRoom(room);
		} catch(Exception e){
			return new JsonResult("500");
		}
		return new JsonResult("00000");
	}

	//删除房间
	@RequestMapping(value = "/deleteRoom/{id}", method = RequestMethod.DELETE)
	public JsonResult deleteRoom(@PathVariable("id") int id){
		try {
			roomService.deleteRoom(id);
		} catch(Exception e){
			return new JsonResult("500");
		}
		return new JsonResult("00000");
	}

	//查询房间是否存在
	@RequestMapping(value = "/isRoomNoExists", method = RequestMethod.GET)
	public JsonResult isRoomNoExists(String roomNo){
		return new JsonResult("00000", roomService.isRoomNoExists(roomNo));
	}

}
